package crivia.ecp.carry.html.table;

import crivia.ecp.carry.html.DO;
import crivia.ecp.common.ECR;
import crivia.ecp.exception.WrongDocumentObject;

public class TableColumn extends DO {
	
	public TableColumn(Table table){
		baseTable = table;
	}

	@Override
	protected String name() {
		return "col";
	}

	@Override
	protected String innerHTML() {
		return null;
	}
	
	private Table baseTable;
	public Table getBaseTable() {
		if (null == baseTable){
			throw new WrongDocumentObject("No Base Table.");
		}
		return baseTable;
	}
	
	private String width = "";
	public String getWidth() {
		return width;
	}
	public TableColumn setWidth(String width) {
		this.width = width;
		return this;
	}
	
	@Override
	public String toString() {
		if (! ECR.hasCondition(width) && ! this.equals(getBaseTable().getLastColGroup())){
			width = (100 / getBaseTable().getColGroup().size()) + "%";
		}
		addAttr("width", width);
		return super.toString();
	}

}
